<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@page import="java.io.PrintWriter"%><%@ page language="java"
	contentType="text/html; charset=ISO-8859-1" import="java.sql.*"
	pageEncoding="ISO-8859-1"%>
<%
	Connection conn = null;
	PreparedStatement psSelect = null;
	String strSelect = null;
	ResultSet rsUserName = null;
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	conn = DriverManager
			.getConnection(
					"jdbc:mysql://localhost:3306/movieshoponline",
					"root", "sa");

	String userName = request.getParameter("q");

	try {
		strSelect = "SELECT * FROM User WHERE username = ? ";

		psSelect = conn.prepareStatement(strSelect);
		psSelect.setString(1, userName);
		rsUserName = psSelect.executeQuery();

		int count;
		if (rsUserName.isAfterLast())
			count = 0;
		else {
			rsUserName.last();
			count = rsUserName.getRow();
		}

		if (count == 1) {
			out.print("This user is ready exist");
		} else {
			out.print("This user can use");
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	try {
		if (psSelect != null) {
			psSelect.close();
		}
		if (conn != null) {
			conn.close();
		}
		if (rsUserName != null) {
			rsUserName.close();
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
%>

